<?php
/*
# ------------------------------------------------------------------------
# JA Job Board component for Joomla 1.5
# ------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
# ------------------------------------------------------------------------
*/


defined('_JEXEC') or die('Retricted Access');

global $option,$jbconfig;
$Itemid = JRequest::getVar('Itemid', 0);
if(isset($this->goto_buynow) && $this->goto_buynow){?>
	<div class="messengers">
		<?php echo JText::_('You have no premium posting left');?>
		<br />
		<a class="button" href="<?php echo JRoute::_('index.php?option='.$option.'&view=japosts&layout=selectplan');?>" title="click here to buy now"><?php echo JText::_('Order Ads')?></a>
	</div>
<?php
	return ;
}
?>
<?php JHTML::_('behavior.modal', 'a.modal'); ?>
<?php
$user = JFactory::getUser();
//JFilterOutput::objectHTMLSafe( $this->item );
JHTML::_('behavior.tooltip');
JHTML::_('behavior.formvalidation');
$profile = getItemByFieldName('ja_profiles','user_id',$this->item->user_id);
$profile = $profile[0];
?>


<div id="jobboard-content">


<script type="text/javascript" language="javascript">
//<![CDATA[
max_location_selection = <?php echo  $jbconfig['posts']->get('maximum_locations',3);?>;
	max_category_selection = <?php echo  $jbconfig['posts']->get('maximum_cats',3);?>;
	function submitbutton(pressbutton) {	
		var sum_location = cal_number_selection('location_id',child_location_id);
		var sum_category = cal_number_selection('cat_id',child_cat_id)
		//Check location selection
		if (sum_location > max_location_selection)
		{
			alert("<?php echo JText::_('Your selected location is out of allow selection number.').' ('.JText::_('Limited is ').$jbconfig['posts']->get('maximum_locations',3).' selections)'; ?>");
			return;
		}
		
		
		
		//Check category selection
		if (sum_category > max_category_selection)
		{
			alert("<?php echo JText::_('Your selected category is out of allow selection number.').' ('.JText::_('Limited is ').$jbconfig['posts']->get('maximum_cats',3).' selections)'; ?>");
			return;
		}
		
		var direct_url_obj = document.getElementById('apply_type1');
		if (direct_url_obj)
		if (direct_url_obj.checked)
			if (form.direct_url.value=='')
			{
				alert('<?php echo JText::_('Direct URL for apply could not be empty'); ?>');
				return;
			}
			
	    form.task.value = pressbutton;
	    form.submit();
		
	}
	
	function show(id){
	    var ele = document.getElementById(id);
	    if(ele.style != null){
	        ele.style.display = ele.style.display == 'none' ? 'block' : 'none';
	    }
	}
	
	function select_direct_url(is_checked)
	{
		var s_direct_url = $('s_direct_url');
		if (is_checked)
		{
			
		s_direct_url.style.display='block';
		}
		else
		{
		s_direct_url.style.display='none';
		}
		
	}
	
	function user_profile_apply_url(text_url)
	{
		form.direct_url.value = text_url;
		document.getElementById('sbox-window').close();
	}
//]]>
</script>

<?php rendfield_JS();?>
<form name="adminForm" class="form-validate" action="<?php echo JURI::root();?>index.php" method="post" enctype="multipart/form-data">
    <div style="width:100%;" class="element-box">
    
    <div class="moduletable job-box">		
		<table class="tabledata jobdetails">
        <?php
        $k=0;
        for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ )
        if ($this->fieldlist[$i]->field_name!='direct_url'){
            $field = $this->fieldlist[$i];
            
            if($field->display=='admin_only' && $user->aid<2) continue;
            
            $field_name = $field->field_name;
            $action = (isset($this->item->id)&&($this->item->id!=0)&&($this->item->id!=null))?'edit':'new';
	        $firstIndex = findFirstField($this->item,$this->fieldlist,$action);
			$lastIndex = findLastField($this->item,$this->fieldlist,$action);
		 	$task = JRequest::getVar("task");
			
        	if($this->item->id && $task!='duplicate'){
            	$input = rendfield($this->item, $field, false, TRUE, false);
            }
            else{
            	$input = rendfield($this->item, $field, false, false, false);
            }
             
            if($field->field_type=='SEPERATOR' && $field->display!='hide_all'){?>
   				</table>
			</div>
	    	<div class="moduletable jobdetails"> 
	  		<?php if($input!=''){?>
				<h3><?php echo $input;?></h3>
			<?php }?>
				<table class="tabledata jobdetails">
		    <?php }else{?>
		               
           <?php if (isset($this->fieldlist[$i-1])){
           	
		           	if (($i==$firstIndex)||($this->fieldlist[$i-1]->field_type=='SEPERATOR'))
			      		$classname = 'first sectiontableentry'.($k+1);
			      	elseif (isset($this->fieldlist[$i-1]))
			      	{
			      		if (isset($this->fieldlist[$i+1]) && ($i==$lastIndex)||(  isset($this->fieldlist[$i+1]->field_type) && $this->fieldlist[$i+1]->field_type=='SEPERATOR'))
				      		$classname = 'last sectiontableentry'.($k+1);
				      	else 
				      		$classname = 'sectiontableentry'.($k+1);
			      	}
			      	else 	
			      		$classname = 'last sectiontableentry'.($k+1);
           	}
           	else 
           		$classname = 'first sectiontableentry'.($k+1);
           	?>
    		<?php if( ($action=='new' && $field->display=='hide_on_new') ||  ($field->display=='hide_all') ){?>
		          <?php echo $input;?>
           	<?php }else{?>				           	
	       		 <tr class="<?php echo $classname; ?>">
	                <td class="col1">
	                <?php echo JText::_($field->label); ?>:
	                </td>
	                
	                <td class="col2">
	                   <?php echo $input;?>
	                </td>
	            </tr> 
            <?php }?>       
            
            <?php $k = 1 - $k;
           }
        }?>
       </table>
    </div>
    </div>
	<table class="tabledata jobdetails">
        <tr>
        		<td class="col1"></td>
            <td class="col2">
                <input class="button" type="button" onclick="submitbutton('save');" value="<?php echo JText::_('Save'); ?>" />
                <input class="button" type="button" onclick="submitbutton('cancel');" value="<?php echo JText::_('Cancel'); ?>" />
            </td>
        </tr>
    </table>
    
    <?php if(isset($this->appliedlist) && count($this->appliedlist)):?>
    <a href="javascript:show('applied-resumes');"><?php echo JText::_('Show/Hide'); ?></a>.
    <div id="applied-resumes" style="display:block;">
    <h3>
       <?php echo JText::_('Number of applications: '. count($this->appliedlist));?>
    </h3>
    <table class="tablelist applicationlist">
        <thead>
            <tr>
                <td><?php echo JText::_('Subject')?></td>
                <td><?php echo JText::_('Resume')?></td>
                <td><?php echo JText::_('Attachment')?></td>
                <td><?php echo JText::_('Applied Date/Time')?></td>
            </tr>
        </thead>
        </tr>
    <?php
    $k = 1;
    for($i = 0, $n = count($this->appliedlist); $i < $n; ++$i){
        $application = $this->appliedlist[$i];
        $k = 1- $k;
        ?>
        <tr class="<?php echo "row$k"; ?>">
            <td><a target="_blank" href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaapplications&task=view&cid[]='. $application->id .'&fromsearch=2&Itemid='. $this->Itemid); ?>"><?php echo $application->title; ?></a></td>
            <td align="center"><a target="_blank" href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaresumes&task=view&cid[]='. $application->resume_id .'&fromsearch=2&Itemid='. $this->Itemid); ?>"><?php echo JText::_('View resume'); ?></a></td>
            <td align="center">
                <?php if($application->attachment):?>
                <a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaapplications&task=download&fromsearch=2&cid[]='. $application->id .'&Itemid='. $this->Itemid); ?>"><?php echo JText::_('Download'); ?></a>
                <?php endif; ?>
            </td>
            <td align="center"><?php echo $application->created_date; ?></td>
        </tr>
        <?php
    }
    ?>
    </table>
    </div>
    <?php endif; ?>
    <?php
    if (!$this->item->id)
    {
    ?>
    	<input type="hidden" name="created_date" value="<?php echo date("Y-m-d H:i:s"); ?>" />
    	<input type="hidden" name="is_hotjob" value="1" />
    <?php
    }
    else 
    {
    ?>
    	<input type="hidden" name="is_hotjob" value="<?php echo $this->item->is_hotjob; ?>" />
    <?php
    }
    ?>
    <input type="hidden" name="user_id" value="<?php echo $user->id; ?>" />
    <input type="hidden" name="apply_url" value="<?php echo $profile->apply_url; ?>" />
	<input type="hidden" name="cid[]" value="<?php echo $this->item->id; ?>" />
    <input type="hidden" name="posted" value="0" />
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="view" value="jajobs" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="layout" value="<?php echo $this->getLayout(); ?>" />
    <input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
    <input type="hidden" name="is_frontend" value="1" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
</div>